import axios from 'axios'

let base = '';

/**
 * 发送json格式的post请求
 * @param url
 * @param params
 * @returns {AxiosPromise}
 */
export const postRequest = (url, params) => {
	return axios({
		method: 'post',
		url: `${base}${url}`,
		data: params,
		headers: {
			'Content-Type': 'application/json'
		}
	})
};


/**
 * get请求, 参数外面有个 params "包裹"
 *  例子:
 *      params: {
 *        name: "zhangsan",
 *        password: "123"
 *      }
 *  实际url是
 *      http://localhost:8080/api/testGetRequest?name=zhangsan&password=123
 *
 * @param url
 * @param params
 * @returns {AxiosPromise}
 */
export const getRequest = (url, params) => {
	return axios({
		method: 'get',
		url: `${base}${url}`,
		params: params              // 注意这里与post方法不同, 实际上是将参数 以 & 拼接在url后面.
	});
};
